package cn.icebreak.cartoon.ui.read;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.icebreak.cartoon.R;
import cn.icebreak.cartoon.base.BaseRecyclerViewHolder;
import cn.icebreak.cartoon.base.CommExRecyclerViewAdapter;
import cn.icebreak.cartoon.global.GlideApp;
import cn.icebreak.utils.DensityUtils;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class CatalogueAdapter extends CommExRecyclerViewAdapter<CatalogueBean, CatalogueAdapter.VHolder> {

    Context context;

    public CatalogueAdapter(Context context, List<CatalogueBean> list) {
        super(list);
        this.context = context;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.adapter_catalogue;
    }

    @Override
    public VHolder createViewHolder(View view) {
        return  new VHolder(view);
    }

    @Override
    public void bindViewHolder(VHolder holder, int position, CatalogueBean bean) {

        holder.tvCatalogueTitle.setText(bean.title);
        holder.tvCatalogueSub.setText(bean.content);

        GlideApp.with(context)
                .load(bean.iconUrl)
                .placeholder(R.mipmap.item)
                .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(DensityUtils.dp2px(context, 4), 0,
                        RoundedCornersTransformation.CornerType.ALL)))
                .into(holder.ivCatalogue);
    }

    static class VHolder extends BaseRecyclerViewHolder {
        @BindView(R.id.iv_catalogue)
        ImageView ivCatalogue;
        @BindView(R.id.tv_catalogue_title)
        TextView tvCatalogueTitle;
        @BindView(R.id.tv_catalogue_sub)
        TextView tvCatalogueSub;
        public VHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}


